(function($) {
	$(function(event) {
		// ********  Change specOffers flag  ********
    	$('#offers').click(function() {
    		var elt = $(this);
    		if (elt.attr('disabled') == 'disabled') {
    			return;
    		}
    		elt.attr('disabled', 'disabled');

    		var userId = $('#userId').val();
    		var status = '0';
    		if (elt.hasClass('offers-not-send')) {
    			status = '1';
    		}
			elt.parents('.offers').append('<img id="ajax-loader" style="vertical-align:middle;" src="./i/ajax-loader-small.gif" />');

    		var result = $.ajax({
    			url: '/a_settings.changeOffers?offers=' + status,
    			type: "GET",
    			timeout: 5000,
    			/*dataType : "json",*/
    			success: function(data) {
	    			if (data > 0) {
	    				if (status == '1') {
	    					elt.removeClass('offers-not-send').addClass('offers-send').attr('title', 'OFFERS_GET_TRUE'.translate());
	    				} else {
	    					elt.removeClass('offers-send').addClass('offers-not-send').attr('title', 'OFFERS_GET_FALSE'.translate());
	    				}
//	    				alert('OFFERS_GET_UPDATE_SUCCESS'.translate());
	    			} else {
	    				alert('OFFERS_GET_UPDATE_ERROR'.translate());
	    			}
					$('#ajax-loader').remove();
	    		},
	    		error: function() {
	    			alert('OFFERS_GET_UPDATE_ERROR'.translate());
					$('#ajax-loader').remove();
	    		}
    		});

    		elt.removeAttr('disabled');
    	});
		// ********  END Change specOffers flag  ********
	});
})(jQuery);